###### RUN THIS SCRIPT FIRST ##### #-------------------------------------------#

# This script loads all packages that are required to reproduce the main results.
# Please make sure that all packages are in the correct version (see below).
# It is important to run these scripts in the right order.

# renv::restore()

# Libraries
library(rio)
library(udpipe)
library(tidyverse)
library(tidylog)
library(tsibble)
library(stringi)
library(quanteda)
library(BTM)
library(vdemdata)
library(lme4)
library(broom.mixed)
library(ggpubr)
library(MetBrewer)
library(textmineR)
library(tidytext)

# R script 1: text_preparation.R
# This script prepares the event descriptions from ACLED for further analysis.
source("Rscripts/text_preparation.R")

# R script 2: topic_models.R
# This script runs the BTM on the lemmatized notes from ACLED.
# This script generates Table 1 and Figure A.2
source("Rscripts/topic_models.R")

# R script 3: descriptive_plots.R
# This script generates Figures 2,3 and 4, as well as Figures A.1
source("Rscripts/descriptive plots.R")

# R script 4: analytical_results.R
# This script generates the regression Table 2 and Figures 4,5 and 6. 
source("Rscripts/analytical_results.R")



# R version 4.1.0 (2021-05-18)
# Platform: x86_64-apple-darwin17.0 (64-bit)
# Running under: macOS Big Sur 11.7.6
# 
# Matrix products: default
# LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
# 
# locale:
#   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# 
# attached base packages:
#   [1] stats     graphics  grDevices datasets  utils     methods   base     
# 
# other attached packages:
#   [1] tidytext_0.3.1      textmineR_3.0.5     MetBrewer_0.1.0     ggpubr_0.4.0        broom.mixed_0.2.9.4
# [6] lme4_1.1-27         Matrix_1.3-3        vdemdata_3.0        BTM_0.3.6           quanteda_3.0.0     
# [11] stringi_1.7.12      tsibble_1.1.1       tidylog_1.0.2       forcats_0.5.1       stringr_1.5.0      
# [16] dplyr_1.1.0         purrr_1.0.1         readr_2.1.2         tidyr_1.3.0         tibble_3.2.0       
# [21] ggplot2_3.4.1       tidyverse_1.3.1     udpipe_0.8.8        rio_0.5.26         
# 
# loaded via a namespace (and not attached):
#   [1] readxl_1.4.0        backports_1.4.1     Hmisc_4.7-0         fastmatch_1.1-0     splines_4.1.0      
# [6] listenv_0.8.0       SnowballC_0.7.0     digest_0.6.31       htmltools_0.5.4     fansi_1.0.4        
# [11] lda_1.4.2           magrittr_2.0.3      checkmate_2.0.0     cluster_2.1.2       tzdb_0.3.0         
# [16] openxlsx_4.2.3      globals_0.15.0      modelr_0.1.8        RcppParallel_5.1.4  timechange_0.2.0   
# [21] anytime_0.3.9       jpeg_0.1-8.1        colorspace_2.1-0    rvest_1.0.2         ggrepel_0.9.1      
# [26] haven_2.5.0         xfun_0.39           crayon_1.5.1        jsonlite_1.8.0      survival_3.2-11    
# [31] countrycode_1.4.0   glue_1.6.2          polyclip_1.10-0     stopwords_2.2       gtable_0.3.1       
# [36] car_3.0-10          abind_1.4-5         scales_1.2.1        DBI_1.1.2           rstatix_0.7.0      
# [41] Rcpp_1.0.10         htmlTable_2.2.1     foreign_0.8-81      clisymbols_1.2.0    Formula_1.2-5      
# [46] htmlwidgets_1.5.3   httr_1.4.3          RColorBrewer_1.1-3  ellipsis_0.3.2      pkgconfig_2.0.3    
# [51] farver_2.1.1        nnet_7.3-16         dbplyr_2.1.1        utf8_1.2.3          tidyselect_1.2.0   
# [56] labeling_0.4.2      rlang_1.0.6         munsell_0.5.0       cellranger_1.1.0    tools_4.1.0        
# [61] cli_3.6.0           generics_0.1.3      broom_0.8.0         evaluate_0.15       fastmap_1.1.0      
# [66] yaml_2.3.5          knitr_1.43          fs_1.5.2            zip_2.2.0           future_1.26.1      
# [71] nlme_3.1-152        xml2_1.3.3          tokenizers_0.2.1    compiler_4.1.0      rstudioapi_0.13    
# [76] curl_4.3.2          png_0.1-7           ggsignif_0.6.1      reprex_2.0.1        tweenr_1.0.2       
# [81] lattice_0.20-44     texreg_1.37.5       grateful_0.2.0      nloptr_1.2.2.2      ggsci_2.9          
# [86] vctrs_0.5.2         pillar_1.8.1        lifecycle_1.0.3     furrr_0.2.2         data.table_1.14.2  
# [91] R6_2.5.1            latticeExtra_0.6-29 renv_0.17.3         RcppProgress_0.4.2  gridExtra_2.3      
# [96] janeaustenr_0.1.5   parallelly_1.31.1   codetools_0.2-18    boot_1.3-28         MASS_7.3-54        
# [101] assertthat_0.2.1    withr_2.5.0         mgcv_1.8-35         parallel_4.1.0      hms_1.1.1          
# [106] grid_4.1.0          rpart_4.1-15        minqa_1.2.4         rmarkdown_2.13      carData_3.0-4      
# [111] ggforce_0.3.3       lubridate_1.9.2     base64enc_0.1-3     tinytex_0.45 